package com.dayuanit.dy15.ebook.bookshop.controller;

import com.dayuanit.dy15.ebook.bookshop.dto.ResponseDTO;
import com.dayuanit.dy15.ebook.bookshop.service.AddressService;
import com.dayuanit.dy15.ebook.bookshop.vo.AddressRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AreaController extends BaseController {

    @Autowired
    private AddressService addressService;

    /**
     * 查询省市区接口
     * @param level
     * @param parentId
     * @return
     */
    @RequestMapping("/address/loadArea")
    public ResponseDTO loadArea(byte level, Long parentId) {
        return ResponseDTO.sucess(addressService.listArea(level, parentId));
    }

    @RequestMapping("/address/addAddress")
    public ResponseDTO addAddress(@RequestBody AddressRequestVO addressRequestVO) {
        addressService.addAddress(addressRequestVO, getUserId());
        return ResponseDTO.sucess();
    }

    @RequestMapping("/address/listAddress")
    public ResponseDTO listAddress() {
        return ResponseDTO.sucess(addressService.listUserAddress(getUserId()));
    }
}
